<template>
  <div class="_wz_cent_main _wz_deptList">
    <Card dis-hover :bordered="true">
      <p slot="title">
        列表
        <span style="color: #ed4014;margin: 0 0 0 10px;font-weight: 600;font-size: 12px;">课件、授权开通，请联系商务人员。</span>
      </p>
      <p slot="extra">
        <Button type="primary" @click="refreshDeptList">刷新</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>


    <Drawer title="配置" v-model="formOperation" width="700" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <deptConfiguration v-if="formOperation" @closeFun="closeFun" :selectData="selectData"></deptConfiguration>
    </Drawer>
    <Drawer title="修改" v-model="modifyTheType" width="900" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <deptDisposition v-if="modifyTheType" @closeFun="closeFun" :selectData="selectData"></deptDisposition>
    </Drawer>


    <Drawer title="查看" v-model="modifySeeType" width="900" :mask-closable="false" :draggable="true">
      <companyDetails v-if="modifySeeType" :selectData="selectData"></companyDetails>
    </Drawer>
    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>
  import wzTbale from "../../../components/table/table";
  import deptConfiguration from "./deptConfiguration";
  import deptDisposition from "../../../components/main/deptDisposition";
  import companyDetails from "../../../components/main/companyDetails";

  export default {
    components: {
      wzTbale,//列表
      deptConfiguration,//列表
      deptDisposition,//修改信息
      companyDetails,//查看
    },
    data() {
      return {
        modifySeeType:false,//查看
        modifyTheType:false,//修改
        spinShow:false,//本页加载
        selectData: {},
        formOperation: false,
        formOperationStyles: {//表单左侧移出css
          height: 'calc(100% - 51px)',
          overflow: 'auto',
          padding: '10px 10px 10px 10px',
          position: 'static'
        },
        tableData: {
          url: this.apiUrl.coreDeptConfigCoreDeptConfigList,//请求地址
          method: 'post',//请求方式
          where: {},//搜索条件
          height: 'auto',//表格高度 auto
          page: false,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {title: '运输企业', minWidth: 260, key: 'deptName'},
            {title: '运输类型', minWidth: 120, key: 'deptTransportName'},
            {title: '运输车辆数', minWidth: 120, key: 'vehicleCount'},
            {title: '货运挂车数', minWidth: 120, key: 'trailerCount'},
            {title: '从业人员数', minWidth: 120, key: 'driverCount'},
            {title: '授权次数', minWidth: 120, key: 'configAuthNumber'},
            {
              title: '学员自动审核', minWidth: 140, render: (h, params) => {
                if (params.row.configDriverVerifyFlag == 1) {
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '开启')
                } else {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未开启')
                }
              }
            },
            {
              title: '培训自动授权', minWidth: 140, render: (h, params) => {
                if (params.row.configDriverAuthFlag == 1) {
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '开启')
                } else {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未开启')
                }
              }
            },
            {
              title: '培训课程订阅', minWidth: 140, render: (h, params) => {
                if (params.row.configTrainSubscriptionFlag == 1) {
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '开启')
                } else {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未开启')
                }
              }
            },
            {
              title: '考试测验订阅', minWidth: 140, render: (h, params) => {
                if (params.row.configExamSubscriptionFlag == 1) {
                  return h('Tag', {props: {type: 'dot',color: 'success'}}, '开启')
                } else {
                  return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未开启')
                }
              }
            },
            // {
            //   title: '授权可见使用', minWidth: 140, render: (h, params) => {
            //     if (params.row.configMaterialSubscriptionFlag == 1) {
            //       return h('Tag', {props: {type: 'dot',color: 'success'}}, '授权')
            //     } else {
            //       return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未授权')
            //     }
            //   }
            // },
            {
              title: '操作', fixed: 'right', width: 160,
              render: (h, params) => {
                let operationButtons = [];
                operationButtons.push(
                  h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.modifySeeType = true
                      }
                    }
                  }, '查看')
                )
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //画像
                operationButtons.push(
                  h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        let that = this;
                        let routeData = that.$router.resolve({
                          name: "deptDetails",
                          query: { uuid: params.row.deptUuid },
                        });
                        window.open(routeData.href, '_blank');
                      }
                    }
                  }, '画像')
                );


                var buttonList = [];
                buttonList.push(h('DropdownItem', {
                  nativeOn: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.formOperation = true
                    }
                  }
                }, '配置'))

                buttonList.push(h('DropdownItem', {
                  nativeOn: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.modifyTheType = true
                    }
                  }
                }, '修改'))
                if (buttonList.length > 0) {
                  if(operationButtons.length > 0){
                    operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                  }
                  operationButtons.push(h('Dropdown', {props: {trigger: "hover", transfer: true}},
                    [
                      h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"}}, '更多▼'),
                      h('DropdownMenu', {slot: "list"}, buttonList)
                    ])
                  )
                }
                return operationButtons;
              }
            },
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
          },
        },
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态

    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
    },
    methods: {//执行的方法
      //刷新
      refreshDeptList() {
        var that = this;
        that.spinShow = true;
        that.axios.post(that.apiUrl.coreDeptConfigCoreDeptConfigInit,{}).then(res => {
          that.spinShow = false;
          if (!!res) {
            that.$Message.success('刷新成功');
            that.$refs.wzTbale.tableLoadData(true);
          }
        }).catch(err => {
          console.log('失败', err);
        })
      },
      //添加修改触发后关闭刷新
      closeFun(data) {
        var that = this;
        if (data) {//添加修改 刷新表单
          that.$refs.wzTbale.tableLoadData();
        }
        that.formOperation = false;
        that.modifyTheType = false;
      },
    },
    watch: {//监听

    },
    props: {//接收来自父组件的数据

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_deptList {

  }
</style>
